package steed.hadmin.action.system;

import java.lang.reflect.ParameterizedType;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;

import steed.action.annotation.Power;
import steed.domain.system.AdminUser;
import steed.exception.runtime.system.FrameworkException;
import steed.ext.domain.user.Role;
import steed.ext.domain.user.User;
import steed.hadmin.action.HadminAction;
import steed.hibernatemaster.domain.BaseDatabaseDomain;
import steed.hibernatemaster.util.DaoUtil;
import steed.util.reflect.ReflectUtil;

@Namespace("/hadmin/system/user")
@ParentPackage(value="steed")
@InterceptorRefs({@InterceptorRef(value="mydefault")})
@Power("管理系统用户")
public class UserAction extends HadminAction{
	
	@Action("index")
	@Override
	public String index() {
		return super.index();
	}

	@Override
	public AdminUser getModel() {
		if (domain == null) {
			domain = ReflectUtil.getInstanceFromProperties("adminUserClass");
		}
		return (AdminUser) domain;
	}

	@Override
	@Action("query")
	public void query() {
		super.query();
	}
	
	@Action(value="update")
	@Power("编辑系统用户")
	public String update(){
		getModel().aesDecodePassword();
		return super.updateNotNullField();
	}
	
	@Action("edit")
	@Power("编辑系统用户")
	public String edit(){
		getReferenceDomainKeys();
		return super.edit();
	}
	
	@Action("delete")
	@Power("删除系统用户")
	@Override
	public String delete() {
		return super.delete();
	}
	
	@Action("add")
	@Power("添加系统用户")
	public String add(){
		getReferenceDomainKeys();
		return steed_forward;
	}
	
	private void getReferenceDomainKeys() {
		setRequestAttribute("roleNameList", DaoUtil.listAllObj(Role.class));
	}
	
	@Action(value="save")
	@Power("添加系统用户")
	public String save(){
		getModel().aesDecodePassword();
		return super.save();
	}
	

	@Override
	protected String[] getListFields() {
		return new String[]{"name","sex","nickName"};
	}
	
	
}
